#ifndef MESSAGE_QUEUE_H
#define MESSAGE_QUEUE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "cx_typedef.h"

typedef struct MessageQueue
{
    cx_uint16_t capacity;
    cx_uint16_t front;
    cx_uint16_t rear;
    unsigned char busy;
    char *buf;
    cx_os_sem_t sem;
}MessageQueue_t;

/**
 * @brief Get queue status
 * 
 * @param queue 
 * @return int the free block of the queue,if ret is a negative,queue is busy
 */
int message_queue_status(MessageQueue_t *queue);

/**
 * @brief Create a new message queue
 * 
 * @param queue_size MessageQueue size
 * @return MessageQueue_t* MessageQueue object
 */
MessageQueue_t* message_queue_new(cx_size_t queue_size);

/**
 * @brief  destroy a message queue
 * 
 * @param queue
 */
void message_queue_free(MessageQueue_t *queue);

/**
 * @brief dequeue function
 * 
 * @param queue 
 * @param buf a buffer to save the date who pop form the queue 
 * @param buf_size buf size
 * @return int how much data was pop,attantion,if ret=0,it declare that there is no data in this queue
 */
int message_queue_dequeue(MessageQueue_t *queue, void *buf, cx_uint32_t buf_size);

/**
 * @brief enqueue function
 * 
 * @param queue 
 * @param buf data buffer
 * @param size buffer size
 * @return int how much data was push,attantion,if ret = 0,it declare that the free space of the queue coundn't contain the buffer
 */
int message_queue_enqueue(MessageQueue_t *queue, void *buf, cx_uint16_t size);

#ifdef __cplusplus
}
#endif

#endif
